C:::::::::::::::::::::OPEN_FILE::::::::::::::::::::::::::::::::::::
C.... This routine is responsible for processing control file(eg.W1990075.bat)
C.... specified in first argument.
C.... after opening the control file,this routine calls GET_INOUT_FILES()
C.... to extract all I/O files from the control file and open them with associated 
C.... unit numbers.
C.... Finally,this routine calls GET_CONTR_PARAMS() to extract some paramter 
C.... values from control file and write them to a file associated with unit 5.
C....

      SUBROUTINE OPEN_FILE() 
	    
      !..USE DFLIB                     !use visual digital fortran library
	                                   
      INTEGER       INPUT           !Input unit for control file
      INTEGER       OUTPUT          !Output unit for log file
	  INTEGER       DATAUNIT        !Unit number for data file
	  CHARACTER*60  ARG_1           !First command line argument
	  CHARACTER*60  FILENAME        !User input file name
	  CHARACTER     ANSWER1         !User input for "y"or "n"
	  CHARACTER*60  ARG_2           !Second command line argument
	  INTEGER       FLAG            !0:polwinds;1:equwinds;2:dhdu
	
      !... the following three lines are not standard Fortran 
      INTEGER(2) n1, status         !n1:indicate which command line argument
                                    !status: needed by GETARG()
      !... get first command line argument
      n1 = 1                     
      CALL GETARG(n1, ARG_1) 
	  FILENAME=ARG_1 
      !... get second command line argument
      n2 = 2
      CALL GETARG(n2,ARG_2)
      FLAG=0
      IF(INDEX(ARG_2,'EQWIND').NE.0) THEN
	    FLAG=1
      ELSE IF (INDEX(ARG_2,'DHDU-NORTH').NE.0) THEN
	    FLAG=2
      ELSE IF (INDEX(ARG_2,'DHDU-SOUTH').NE.0) THEN
	    FLAG=3
	  ENDIF  
		         	      
      !... open input control file
  	  INPUT=49                      
      OPEN(INPUT,FILE=FILENAME,STATUS='OLD',ERR=350) 	
      !...extract I/O files and their unit numbers from .RUN file 
	
	  CALL GET_INOUT_FILES(INPUT,FLAG)
	
      !... rewind .RUN file and extract parameters from it and  
      !... store these parameters into the file which is associated with unit 5
	
	  REWIND(INPUT)
      CALL GET_CONTR_PARAMS(INPUT,5)
	  REWIND(5)
	  GO TO 400
	    
 350  WRITE(*,*) 'FILE', FILENAME ,'NOT EXIST!'
 400  CLOSE(INPUT)
      END


